//
//  UIBarButtonItem + Extension.swift
//  1026SwiftSinaWeiBo
//
//  Created by Apple on 15/10/29.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit


extension UIBarButtonItem {

    //swift 类的延展中 只能写便利构造函数
    //重写便利构造函数
    convenience init(imageName: String) {
        
        let button = UIButton()
        
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        
        button.sizeToFit()
        
        self.init(customView: button)
    }
    
    
    class func addNavigationItem(imageName: String) -> UIBarButtonItem {
        
        let button = UIButton()
        
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        
        button.sizeToFit()
        
        return UIBarButtonItem(customView: button)
    }
}